/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.ui;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import org.kommando.core.Displayable;

/**
 * {@link ListCellRenderer} implementation for displaying {@link Displayable}s.
 * 
 * @author Peter De Bruycker
 */
public class DisplayableListCellRenderer extends DefaultListCellRenderer {

    // TODO this class contains code very similary to the ResultListCellRenderer
    
    private static final long serialVersionUID = 1L;

    private Dimension iconSize;

    public DisplayableListCellRenderer(Dimension iconSize) {
        this.iconSize = iconSize;
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
            boolean cellHasFocus) {
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

        Displayable displayable = (Displayable) value;

        setText("<html><body><b>" + displayable.getName() + "</b><p>" + displayable.getDescription());
        setIcon(IconHelper.getIcon(displayable, iconSize));

        return this;
    }

}
